package com.redis.controller;


import com.redis.entity.TBook;
import com.redis.service.ITBookService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yuyongli
 * @since 2023-07-03
 */
@RestController
@RequestMapping("/t-book")
public class TBookController {

    //
    @Resource
    private ITBookService bookService;

    @GetMapping
    public List<TBook> getAll(){
        List<TBook> list = bookService.list1();
        return list;
    }

    // 根据id 查询图书的信息

    @GetMapping("{id}")
    public TBook getById(@PathVariable Integer id){
        TBook byId = bookService.getById1(id);
        return byId;
    }

    @PostMapping
    public TBook addTbook(TBook tBook){
        bookService.save1(tBook);
        return tBook;
    }

    // 删除
    @DeleteMapping("{id}")
    public void delTbook(@PathVariable Integer id){
         bookService.removeById1(id);
    }

}

